package com.itheima.service.impl;

import com.itheima.domain.User;
import com.itheima.domain.UserExample;
import com.itheima.mapper.UserMapper;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByTelephone(String telephone) {
        // 手机号作为条件
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria = userExample.createCriteria();
        criteria.andTelephoneEqualTo(telephone);
        List<User> list = userMapper.selectByExample(userExample);

        // 集合处理
        if (list !=null && list.size()==1) {
            return list.get(0);
        }

        return null;
    }
}
